package com.ict.ms.controller;



import com.ict.ms.area.facade.api.IAreaOpeService;
import com.ict.ms.area.facade.model.Area;
import com.ict.ms.trackPlayBack.facade.hive.service.AreaPlayBackService;
import com.ict.ms.trackPlayBack.facade.api.IHistoryService;
import com.ict.ms.realTime.facade.common.SplitUtils;
import com.ict.ms.common.StateEnum;
import com.ict.ms.common.StateMsg;
import com.ict.ms.trackPlayBack.facade.redis.pojo.Fuse;
import com.ict.ms.trackPlayBack.facade.redis.redisService.TrackFuseService;
import com.ict.ms.trackPlayBack.facade.dto.*;
import com.ict.ms.dto.*;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by chenlong on 2016/11/17.
 */

/**
 * 态势回放
 */

@Controller
@RequestMapping({"/track"})
public class ShipsTrackFuseController {
    @Resource
    TrackFuseService trackFuseService;
    @Resource
    AreaPlayBackService areaPlayBackService;

    @Resource
    IHistoryService historyService;//mysql
    @Resource
    IAreaOpeService areaOpeService;

    /**
     * 多船态势回放
     *
     * @param map
     * @param modeArr
     * @param shipIdArr
     * @param startTime
     * @param endTime
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "moreship.do", method = RequestMethod.POST)
    public String ShipsTrackFuse(ModelMap map, @RequestParam(value = "modeArr", required = false) String modeArr,
                                 @RequestParam(value = "shipIdArr", required = false) String shipIdArr,
                                 @RequestParam(value = "startTime", required = false) int startTime,
                                 @RequestParam(value = "endTime", required = false) int endTime) {

        String[] modeArray;
        String[] shipArray;

        String msg;
        String jsonStr;
        String md;

        if (modeArr.equals("0")) {
            try {
                shipArray = SplitUtils.MDVNumSplit_StrArray(shipIdArr);

                int minTime = Integer.MAX_VALUE;
                int maxTime = Integer.MIN_VALUE;

                List<FuseArray> fuseArrayList = new ArrayList<FuseArray>();
                for (int i = 0; i < shipArray.length; i++) {
                    md = "MDV" + shipArray[i];

                    List<Fuse> trackFuseList = trackFuseService.getFuse_original(md, startTime, endTime);
                    if (trackFuseList.size()== 0) {
                        /*msg = "获取指定目标信息失败";
                        map.addAttribute("error", msg);
                        jsonStr = StateMsg.toJson(-1, map);
                        return jsonStr;*/
                        continue;
                    }

                    //取所有船舶起始时间和结束时间的最大值和最小值
                    if (minTime > trackFuseList.get(0).getTi()) {
                        minTime = trackFuseList.get(0).getTi();
                    }
                    if (maxTime < trackFuseList.get(trackFuseList.size() - 1).getTi()) {
                        maxTime = trackFuseList.get(trackFuseList.size() - 1).getTi();
                    }

                    FuseArray fuseArray = new FuseArray();
                    fuseArray.setNum(Integer.parseInt(shipArray[i]));
                    fuseArray.setMode(Integer.parseInt(modeArr));
                    fuseArray.setPosList(trackFuseList);

                    fuseArrayList.add(fuseArray);
                }

                map.addAttribute("minTime", minTime);
                map.addAttribute("maxTime", maxTime);
                map.addAttribute("shipList", fuseArrayList);
            } catch (Exception e) {
                msg = "获取指定目标信息失败";
                map.addAttribute("error", msg);
                jsonStr = StateMsg.toJson(-3, map);
                return jsonStr;
            }
        } else {
            try {
                modeArray = SplitUtils.MDVNumSplit_StrArray(modeArr);
                shipArray = SplitUtils.MDVNumSplit_StrArray(shipIdArr);

                if (modeArray.length == shipArray.length) {
                    int minTime = Integer.MAX_VALUE;
                    int maxTime = Integer.MIN_VALUE;

                    List<FuseArray> fuseArrayList = new ArrayList<FuseArray>();
                    for (int i = 0; i < shipArray.length; i++) {
                        md = "ODV" + shipArray[i] + "_" + modeArray[i];


                        List<Fuse> trackFuseList = trackFuseService.getFuse_original(md, startTime, endTime);
                        if (trackFuseList.size() == 0) {
                            /*msg = "获取指定目标信息失败";
                            map.addAttribute("error", msg);
                            jsonStr = StateMsg.toJson(-1, map);
                            System.out.println("null");*/
                            continue;
                            //return jsonStr;
                        }

                        //取所有船舶起始时间和结束时间的最大值和最小值
                        if (minTime > trackFuseList.get(0).getTi()) {
                            minTime = trackFuseList.get(0).getTi();
                        }
                        if (maxTime < trackFuseList.get(trackFuseList.size() - 1).getTi()) {
                            maxTime = trackFuseList.get(trackFuseList.size() - 1).getTi();
                        }
                        FuseArray fuseArray = new FuseArray();
                        fuseArray.setNum(Integer.parseInt(shipArray[i]));
                        fuseArray.setMode(Integer.parseInt(modeArray[i]));
                        fuseArray.setPosList(trackFuseList);
                        fuseArrayList.add(fuseArray);
                    }

                    map.addAttribute("minTime", minTime);
                    map.addAttribute("maxTime", maxTime);
                    map.addAttribute("shipList", fuseArrayList);
                } else {
                    msg = "目标输入参数个数不匹配";
                    map.addAttribute("error", msg);
                    jsonStr = StateMsg.toJson(-4, map);
                    return jsonStr;
                }
            } catch (Exception e) {
                msg = "获取指定目标信息失败";
                map.addAttribute("error", msg);
                jsonStr = StateMsg.toJson(-5, map);
                return jsonStr;
            }
        }

        jsonStr = StateMsg.toJson(1, map);
        return jsonStr;
    }

    /**
     * 区域态势回放--hive版本_chenlong
     *
     * @param map
     * @param ldlon
     * @param ldlat
     * @param rulon
     * @param rulat
     * @param startTime
     * @param endTime
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "hisAreaPlayBackHive.do", method = RequestMethod.POST)
    public String areaPlayBack(ModelMap map,
                               @RequestParam(value = "ldlon", required = false) double ldlon,
                               @RequestParam(value = "ldlat", required = false) double ldlat,
                               @RequestParam(value = "rulon", required = false) double rulon,
                               @RequestParam(value = "rulat", required = false) double rulat,
                               @RequestParam(value = "startTime", required = false) int startTime,
                               @RequestParam(value = "endTime", required = false) int endTime,
                               @RequestParam(value = "limit", required = false) int limit,
                               @RequestParam(value = "mode", required = false) int mode) {
        String jsonStr = "";
        AreaParams areaParams = new AreaParams((int) ldlon * 600000, (int) ldlat * 600000, (int) rulon * 600000,
                (int) rulat * 600000, startTime, endTime);

        ResultObjWithCount resultObj = areaPlayBackService.areaTrackPlayBack(areaParams, limit, mode);

        if (resultObj.getState() == -1) {
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SQLExcuteError, map);
        } else if (resultObj.getState() == 0) {
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SelectNull, map);
        } else {
//            List<MapFusePlayBackList> lists=(List<MapFusePlayBackList>)resultObj.getObj();
            map.addAttribute("shipList", resultObj.getObj());
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.Success_All, map);
        }

        return jsonStr;
    }

    /**
     * 区域态势回放--矩形--mysql版本
     *
     * @param map
     * @param ldlon
     * @param ldlat
     * @param rulon
     * @param rulat
     * @param startTime
     * @param endTime
     * @param limit
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "hisAreaPlayBack.do", method = RequestMethod.POST)
    public String hisAreaPlayBack(ModelMap map,
                                  @RequestParam(value = "ldlon", required = false) double ldlon,
                                  @RequestParam(value = "ldlat", required = false) double ldlat,
                                  @RequestParam(value = "rulon", required = false) double rulon,
                                  @RequestParam(value = "rulat", required = false) double rulat,
                                  @RequestParam(value = "startTime", required = false) int startTime,
                                  @RequestParam(value = "endTime", required = false) int endTime,
                                  @RequestParam(value = "limit", required = false) int limit,
                                  @RequestParam(value = "mode", required = false) int mode) {

        String jsonStr = "";
//        System.out.println("传入经纬度："+ldlon+","+ldlat+","+rulon+","+rulat);

        int intX60W_ldlon = (int) (ldlon * 600000);
        int intX60W_ldlat = (int) (ldlat * 600000);
        int intX60W_rulon = (int) (rulon * 600000);
        int intX60W_rulat = (int) (rulat * 600000);

//        System.out.println("X60W以后的经纬度："+intX60W_ldlon+","+intX60W_ldlat+","+intX60W_rulon+","+intX60W_rulat);

        AreaParams areaParams = new AreaParams(intX60W_ldlon, intX60W_ldlat, intX60W_rulon,
                intX60W_rulat, startTime, endTime, limit);

        ResultObjWithCount resultObj = historyService.getHistoryDegInfo(areaParams, mode);
        if (resultObj.getState() == -1) {
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SQLExcuteError, map);
        } else if (resultObj.getState() == 0) {
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SelectNull, map);
        } else {
//            List<MapFusePlayBackList> lists=(List<MapFusePlayBackList>)resultObj.getObj();
            map.addAttribute("shipList", resultObj.getObj());
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.Success_All, map);
        }

        return jsonStr;
    }

    /**
     * 圆形区域态势回放
     *
     * @param map
     * @param cirlon
     * @param cirlat
     * @param ridius
     * @param startTime
     * @param endTime
     * @param limit
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "hisPlayBackCircular.do", method = RequestMethod.POST)
    public String hisPlayBackCircular(ModelMap map,
                                      @RequestParam(value = "cirlon", required = false) double cirlon,
                                      @RequestParam(value = "cirlat", required = false) double cirlat,
                                      @RequestParam(value = "radius", required = false) double ridius,
                                      @RequestParam(value = "startTime", required = false) int startTime,
                                      @RequestParam(value = "endTime", required = false) int endTime,
                                      @RequestParam(value = "mode", required = false) int mode,
                                      @RequestParam(value = "limit", required = false) int limit) {
        String jsonStr = "";

        //通过圆形计算出外切矩形
        //半径（米）转成最大经度和最大纬度
        double lonRidius = ridius / 110000;//此处取赤道最大值
        double latRidius = ridius / 110000;

        int intX60W_ldlon = (int) ((cirlon - lonRidius) * 600000);
        int intX60W_ldlat = (int) ((cirlat - latRidius) * 600000);
        int intX60W_rulon = (int) ((cirlon + lonRidius) * 600000);
        int intX60W_rulat = (int) ((cirlat + latRidius) * 600000);

        AreaParams areaParams = new AreaParams(intX60W_ldlon, intX60W_ldlat, intX60W_rulon,
                intX60W_rulat, startTime, endTime, limit);

        Circular circular = new Circular(cirlon, cirlat, ridius);

        ResultObjWithCount resultObj = historyService.hisPlayBackCircular(mode, areaParams, circular);
        if (resultObj.getState() == -1) {
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SQLExcuteError, map);
        } else if (resultObj.getState() == 0) {
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SelectNull, map);
        } else {
//            List<MapFusePlayBackList> lists=(List<MapFusePlayBackList>)resultObj.getObj();
            map.addAttribute("shipList", resultObj.getObj());
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.Success_All, map);
        }

        return jsonStr;
    }

    /**
     * 扇（环）形区域态势回放
     *
     * @param map
     * @param cirlon
     * @param cirlat
     * @param ridius
     * @param radsmal
     * @param startDeg
     * @param endDeg
     * @param startTime
     * @param endTime
     * @param mode
     * @param limit
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "hisPlayBackSector.do", method = RequestMethod.POST)
    public String hisPlayBackSector(ModelMap map,
                                    @RequestParam(value = "lon", required = false) double cirlon,
                                    @RequestParam(value = "lat", required = false) double cirlat,
                                    @RequestParam(value = "radius", required = false) double ridius,
                                    @RequestParam(value = "radsmal", required = false) double radsmal,
                                    @RequestParam(value = "startDeg", required = false) double startDeg,
                                    @RequestParam(value = "endDeg", required = false) double endDeg,
                                    @RequestParam(value = "startTime", required = false) int startTime,
                                    @RequestParam(value = "endTime", required = false) int endTime,
                                    @RequestParam(value = "mode", required = false) int mode,
                                    @RequestParam(value = "limit", required = false) int limit) {
        String jsonStr = "";
        //通过圆形计算出外切矩形
        //半径（米）转成最大经度和最大纬度
        double lonRidius = ridius / 110000;//此处取赤道最大值
        double latRidius = ridius / 110000;

        int intX60W_ldlon = (int) ((cirlon - lonRidius) * 600000);
        int intX60W_ldlat = (int) ((cirlat - latRidius) * 600000);
        int intX60W_rulon = (int) ((cirlon + lonRidius) * 600000);
        int intX60W_rulat = (int) ((cirlat + latRidius) * 600000);

        AreaParams areaParams = new AreaParams(intX60W_ldlon, intX60W_ldlat, intX60W_rulon,
                intX60W_rulat, startTime, endTime, limit);

        System.out.println("外切矩形左下角点Lon：" + intX60W_ldlon + ",Lat：" + intX60W_ldlat + ",右上角的点Lon：" + intX60W_rulon + ",Lat：" + intX60W_rulat);

        CircularSector circularSector = new CircularSector(cirlon, cirlat, ridius, radsmal, startDeg, endDeg);

        ResultObjWithCount resultObj = historyService.hisPlayBackSector(mode, areaParams, circularSector);
        if (resultObj.getState() == -1) {
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SQLExcuteError, map);
        } else if (resultObj.getState() == 0) {
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SelectNull, map);
        } else {
//            List<MapFusePlayBackList> lists=(List<MapFusePlayBackList>)resultObj.getObj();
            map.addAttribute("shipList", resultObj.getObj());
            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.Success_All, map);
        }

        return jsonStr;
    }

    /**
     * @param map
     * @param lonStrArr
     * @param latStrArr
     * @param startTime
     * @param endTime
     * @param mode
     * @param limit
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "hisPlayBackPolygons.do", method = RequestMethod.POST)
    public String areaSetAddPolygons(ModelMap map, @RequestParam(value = "lonStrArr", required = false) String lonStrArr,
                                     @RequestParam(value = "latStrArr", required = false) String latStrArr,
                                     @RequestParam(value = "startTime", required = false) int startTime,
                                     @RequestParam(value = "endTime", required = false) int endTime,
                                     @RequestParam(value = "mode", required = false) int mode,
                                     @RequestParam(value = "limit", required = false) int limit) {

        String msg;
        String jsonStr = "";
        try {
            String[] lonArr = com.ict.ms.realTime.facade.common.SplitUtils.MDVNumSplit_StrArray(lonStrArr);
            String[] latArr = com.ict.ms.realTime.facade.common.SplitUtils.MDVNumSplit_StrArray(latStrArr);
            if (lonArr.length != latArr.length) {
                msg = "参数错误";
                map.addAttribute("result", msg);
                jsonStr = StateMsg.toJson(-2, map);
                return jsonStr;
            } else {

                Double[] point_x = new Double[lonArr.length];
                Double[] point_y = new Double[latArr.length];

                for (int i = 0; i < lonArr.length; i++) {
                    point_x[i] = Double.parseDouble(lonArr[i]);
                    point_y[i] = Double.parseDouble(latArr[i]);
                }

                ArrayList<Double> point_x_list = new ArrayList<Double>(Arrays.asList(point_x));
                ArrayList<Double> point_y_list = new ArrayList<Double>(Arrays.asList(point_y));

                //得到多边形外切矩形用于sql语句筛选目标
                double minLon = point_x[0];
                double minLat = point_y[0];
                double maxLon = point_x[0];
                double maxLat = point_y[0];

                for (int j = 0; j < point_x.length; j++) {
                    if (point_x[j] < minLon) {
                        minLon = point_x[j];
                    }
                    if (point_x[j] > maxLon) {
                        maxLon = point_x[j];
                    }

                    if (point_y[j] < minLat) {
                        minLat = point_y[j];
                    }
                    if (point_y[j] > maxLat) {
                        maxLat = point_y[j];
                    }
                }

                int intX60W_ldlon = (int) (minLon * 600000);
                int intX60W_ldlat = (int) (minLat * 600000);
                int intX60W_rulon = (int) (maxLon * 600000);
                int intX60W_rulat = (int) (maxLat * 600000);

//                System.out.println("X60W以后的外切矩形的经纬度："+minLon+","+minLat+","+maxLon+","+maxLat);

                AreaParams areaParams = new AreaParams(intX60W_ldlon, intX60W_ldlat, intX60W_rulon,
                        intX60W_rulat, startTime, endTime, limit);

                ResultObjWithCount resultObj = historyService.hisPlayBackPolygons(mode, areaParams, point_x_list, point_y_list);
                if (resultObj.getState() == -1) {
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SQLExcuteError, map);
                } else if (resultObj.getState() == 0) {
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SelectNull, map);
                } else {
//            List<MapFusePlayBackList> lists=(List<MapFusePlayBackList>)resultObj.getObj();
                    map.addAttribute("shipList", resultObj.getObj());
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.Success_All, map);
                }

                return jsonStr;
            }
        } catch (Exception e) {
            msg = "参数错误";
            map.addAttribute("result", msg);
            jsonStr = StateMsg.toJson(-2, map);
            return jsonStr;
        }
    }

    /*
    * 选择区域态势回放*/
    @ResponseBody
    @RequestMapping(value = "hisSelectAareaState.do" ,method = RequestMethod.POST)
    public String selectAareaState(ModelMap map,
                                      @RequestParam(value="id", required = false) int id,
                                      @RequestParam(value = "startTime",required = false) int startTime,
                                      @RequestParam(value = "endTime",required = false)int endTime,
                                      @RequestParam(value = "limit",required = false)int limit,
                                      @RequestParam(value = "mode",required = false)int mode){
        String msg = "";
        String jsonStr = "";
        Area area = areaOpeService.getArea(id,255);
        int shap = area.getShape();
        switch (shap){
            //圆形
            case 1:
                int ridius_1 = area.getRadius();
                int cirlon_1 = area.getCentreLon();
                int cirlat_1 = area.getCentreLat();

                double lonRidius = ridius_1;//此处取赤道最大值
                double latRidius = ridius_1;

                int intX60W_ldlon_1 = (int) ((cirlon_1 - lonRidius));
                int intX60W_ldlat_1 = (int) ((cirlat_1 - latRidius));
                int intX60W_rulon_1 = (int) ((cirlon_1 + lonRidius));
                int intX60W_rulat_1 = (int) ((cirlat_1 + latRidius));

                AreaParams areaParams_1 = new AreaParams(intX60W_ldlon_1, intX60W_ldlat_1, intX60W_rulon_1,
                        intX60W_rulat_1, startTime, endTime, limit);

                Circular circular = new Circular(cirlon_1, cirlat_1, ridius_1);

                ResultObjWithCount resultObj_1 = historyService.hisPlayBackCircular(mode, areaParams_1, circular);
                if (resultObj_1.getState() == -1) {
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SQLExcuteError, map);
                } else if (resultObj_1.getState() == 0) {
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SelectNull, map);
                } else {
                    map.addAttribute("shipList", resultObj_1.getObj());
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.Success_All, map);
                }
                return jsonStr;
            case 2:
                //矩形
                int ldlat = area.getLdlat();
                int ldlon = area.getLdlon();
                int rulat = area.getRulat();
                int rulon = area.getRulon();

                int intX60W_ldlon_2 = (int) (ldlon);
                int intX60W_ldlat_2 = (int) (ldlat);
                int intX60W_rulon_2 = (int) (rulon);
                int intX60W_rulat_2 = (int) (rulat);

                AreaParams areaParams_2 = new AreaParams(intX60W_ldlon_2, intX60W_ldlat_2, intX60W_rulon_2,
                        intX60W_rulat_2, startTime, endTime, limit);

                ResultObjWithCount resultObj_2 = historyService.getHistoryDegInfo(areaParams_2, mode);
                if (resultObj_2.getState() == -1) {
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SQLExcuteError, map);
                } else if (resultObj_2.getState() == 0) {
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SelectNull, map);
                } else {
                    map.addAttribute("shipList", resultObj_2.getObj());
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.Success_All, map);
                }

            case 3:
                //多边形
                Integer lonStrArr = area.getLdlon();
                Integer latStrArr = area.getLdlat();
                try {
                    String[] lonArr = com.ict.ms.realTime.facade.common.SplitUtils.MDVNumSplit_StrArray(lonStrArr.toString());
                    String[] latArr = com.ict.ms.realTime.facade.common.SplitUtils.MDVNumSplit_StrArray(latStrArr.toString());
                    if (lonArr.length != latArr.length) {
                        msg = "参数错误";
                        map.addAttribute("result", msg);
                        jsonStr = StateMsg.toJson(-2, map);
                        return jsonStr;
                    } else {

                        Double[] point_x = new Double[lonArr.length];
                        Double[] point_y = new Double[latArr.length];

                        for (int i = 0; i < lonArr.length; i++) {
                            point_x[i] = Double.parseDouble(lonArr[i]);
                            point_y[i] = Double.parseDouble(latArr[i]);
                        }

                        ArrayList<Double> point_x_list = new ArrayList<Double>(Arrays.asList(point_x));
                        ArrayList<Double> point_y_list = new ArrayList<Double>(Arrays.asList(point_y));

                        //得到多边形外切矩形用于sql语句筛选目标
                        double minLon = point_x[0];
                        double minLat = point_y[0];
                        double maxLon = point_x[0];
                        double maxLat = point_y[0];

                        for (int j = 0; j < point_x.length; j++) {
                            if (point_x[j] < minLon) {
                                minLon = point_x[j];
                            }
                            if (point_x[j] > maxLon) {
                                maxLon = point_x[j];
                            }

                            if (point_y[j] < minLat) {
                                minLat = point_y[j];
                            }
                            if (point_y[j] > maxLat) {
                                maxLat = point_y[j];
                            }
                        }

                        int intX60W_ldlon_3 = (int) (minLon);
                        int intX60W_ldlat_3 = (int) (minLat);
                        int intX60W_rulon_3 = (int) (maxLon);
                        int intX60W_rulat_3 = (int) (maxLat);
                        AreaParams areaParams_3 = new AreaParams(intX60W_ldlon_3, intX60W_ldlat_3, intX60W_rulon_3,
                                intX60W_rulat_3, startTime, endTime, limit);

                        ResultObjWithCount resultObj_3 = historyService.hisPlayBackPolygons(mode, areaParams_3, point_x_list, point_y_list);
                        if (resultObj_3.getState() == -1) {
                            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SQLExcuteError, map);
                        } else if (resultObj_3.getState() == 0) {
                            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SelectNull, map);
                        } else {
                            map.addAttribute("shipList", resultObj_3.getObj());
                            jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.Success_All, map);
                        }

                    }
                } catch (Exception e) {
                    msg = "参数错误";
                    map.addAttribute("result", msg);
                    jsonStr = StateMsg.toJson(-2, map);
                }
            case 4:
                //扇环形
                int ridius_4 = area.getRadius();
                double lonRidius_4 = ridius_4 ;//此处取赤道最大值
                double latRidius_4 = ridius_4 ;
                int radsmal = area.getRadsmal();
                int cirlon_4 = area.getCentreLon();
                int cirlat_4= area.getCentreLat();
                double startDeg = area.getStart_deg();
                double endDeg = area.getEnd_deg();

                int intX60W_ldlon = (int) ((cirlon_4 - lonRidius_4));
                int intX60W_ldlat = (int) ((cirlat_4 - latRidius_4));
                int intX60W_rulon = (int) ((cirlon_4 + lonRidius_4));
                int intX60W_rulat = (int) ((cirlat_4 + latRidius_4));

                AreaParams areaParams_4 = new AreaParams(intX60W_ldlon, intX60W_ldlat, intX60W_rulon,
                        intX60W_rulat, startTime, endTime, limit);

                System.out.println("外切矩形左下角点Lon：" + intX60W_ldlon + ",Lat：" + intX60W_ldlat + ",右上角的点Lon：" + intX60W_rulon + ",Lat：" + intX60W_rulat);

                CircularSector circularSector = new CircularSector(cirlon_4, cirlat_4, ridius_4, radsmal, startDeg, endDeg);

                ResultObjWithCount resultObj_4 = historyService.hisPlayBackSector(mode, areaParams_4, circularSector);
                if (resultObj_4.getState() == -1) {
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SQLExcuteError, map);
                } else if (resultObj_4.getState() == 0) {
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.SelectNull, map);
                } else {
                    map.addAttribute("shipList", resultObj_4.getObj());
                    jsonStr = StateMsg.toJsonOSE(StateEnum.StateCode.Success_All, map);
                }

        }
        return jsonStr;
    }
}